<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/common/mytags.jsp"%>

<html>
<head>
<%@ include file="/common/easyui.jsp"%>
<script type="text/javascript">
	function isValid() {
		$('#dbName').validatebox({
			required : true,
			missingMessage : '请输入有效的数据库名！'
		});
		if (!$('#dbName').validatebox('isValid'))
			return false;
		$('#dbType').validatebox({
			required : true,
			missingMessage : '请输入有效的类型！'
		});
		if (!$('#dbType').validatebox('isValid'))
			return false;
		$('#dbUrl').validatebox({
			required : true,
			missingMessage : '请输入有效的地址！'
		});
		if (!$('#dbUrl').validatebox('isValid'))
			return false;
		$('#dbAccount').validatebox({
			required : true,
			missingMessage : '请输入有效的账号！'
		});
		if (!$('#dbAccount').validatebox('isValid'))
			return false;
		$('#dbPwd').validatebox({
			required : true,
			missingMessage : '请输入有效的密码！'
		});
		if (!$('#dbPwd').validatebox('isValid'))
			return false;

		return true;
	}

	function sub() {
		if (!isValid())
			return;
			var dbName = $.trim($('#dbName').val());
			var dbType = $.trim($('#dbType').val());
			var dbUrl = $.trim($('#dbUrl').val());
			var dbAccount = $.trim($('#dbAccount').val());
			var dbPwd = $.trim($('#dbPwd').val());
		var url='${ctx}/adminManage/auto/autoDb/saveForAjax.do';
		if('${param.id}'!=''){
			url='${ctx}/adminManage/auto/autoDb/updateForAjax.do';
		}
		$.ajax({
			type : 'post',
			url : url,
			data : {
					id : '${param.id}',
					dbName : dbName,
					dbType : dbType,
					dbUrl : dbUrl,
					dbAccount : dbAccount,
					dbPwd : dbPwd
			},
			dataType : 'json',
			success : function(data) {
				if (data.result) {
					$.messager.alert('提示', '操作成功！', 'info',function(){
						parent.$('#win').dialog('close');
						parent.$('#dataTable').datagrid('reload');
					});
				} else {
					$.messager.alert('提示', '操作失败！', 'error');
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				$.messager.alert('提示', '操作失败！<br />' + errorThrown, 'error');
			}
		});
	}
	
	function cancel() {
		$('#editDiv').dialog('close');
	}
</script>
<link rel="stylesheet" href="${ctx}/plug-in/Validform/css/style.css" type="text/css"/>
<link rel="stylesheet" href="${ctx}/plug-in/Validform/css/tablefrom.css" type="text/css"/>
</head>

<table class="formtable">
	<input type="hidden" name="id" value="${autoDb.id}"/>
	<tr>
		<td width="15%" align="right"><label class="Validform_label">数据库名：</label></td>
		<td class="value">
			<input id="dbName" type="text" value="${autoDb.dbName}" />
		</td>
	</tr>
	<tr>
		<td align="right"><label class="Validform_label">类型：</label></td>
		<td class="value">
			<input id="dbType" type="text" value="${autoDb.dbType}" />
		</td>
	</tr>
	<tr>
		<td align="right"><label class="Validform_label">地址：</label></td>
		<td class="value">
			<input id="dbUrl" type="text" value="${autoDb.dbUrl}" />
		</td>
	</tr>
	<tr>
		<td align="right"><label class="Validform_label">账号：</label></td>
		<td class="value">
			<input id="dbAccount" type="text" value="${autoDb.dbAccount}" />
		</td>
	</tr>
	<tr>
		<td align="right"><label class="Validform_label">密码：</label></td>
		<td class="value">
			<input id="dbPwd" type="text" value="${autoDb.dbPwd}" />
		</td>
	</tr>
	<tr>
		<td colspan="2" align="center">
			<a id="saveButton" class="easyui-linkbutton" icon="icon-ok" onclick="sub()">确定</a>
			<a class="easyui-linkbutton" icon="icon-cancel" onclick="cancel()">取消</a>
		</td>
	</tr>
</table>